package lazy2.util;

import java.io.*;

public abstract class CloseableHandler<T extends Closeable> extends Handler {
	// Property
	protected T closeable;
	
	// Method hooks
	protected void handleIOException(IOException e) {e.printStackTrace();}
	
	// Constructor
	public CloseableHandler(T closeable) {
		if(closeable!=null) {
			this.closeable = closeable;
			process();
		}
	}
	
	// Internal methods
	private void process() {
		try {
			handle();
		} catch (IOException e) {
			handleIOException(e);
		} catch (Exception e) {
			handleException(e);
		} finally {
			IOUtil.closeAll(closeable);
		}
	}
}
